package migrations

import (
	"database/sql"
	"time"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/migrate"

	"gorm.io/gorm"
)

// http://sql2struct.atotoa.com/
func init() {

	// 行程-乘客订单表
	type TripRider struct {
		models.BaseModel

		UserId       uint64    `gorm:"column:user_id;comment:用户id;index;" db:"user_id" json:"user_id" form:"user_id"`
		TripId       uint64    `gorm:"column:trip_id;comment:行程id;" db:"trip_id" json:"trip_id" form:"trip_id"`                                                 //乘车人ID
		RiderId      uint64    `gorm:"column:rider_id;comment:乘车人id;" db:"rider_id" json:"rider_id" form:"rider_id"`                                            //乘车人ID
		BookingSeats int8      `gorm:"column:booking_seats;comment:预定座位数;" db:"booking_seats" json:"booking_seats" form:"booking_seats"`                        //预定座位数
		TotalPrice   float64   `gorm:"column:total_price;comment:总价" db:"total_price" json:"total_price" form:"total_price"`                                    //总价
		Commission   float64   `gorm:"column:commission;comment:佣金;" db:"commission" json:"commission" form:"commission"`                                       //佣金
		Deadline     time.Time `gorm:"column:deadline;type:timestamp;comment:当用户找车时，找车截止时间;" db:"deadline" json:"deadline" form:"deadline"`                     //拼车截止时间
		MatchStatus  int8      `gorm:"column:match_status;comment:匹配状态 1未匹配 2已匹配;" db:"match_status" json:"match_status" form:"match_status"`                   //匹配状态，1：未匹配，2：已匹配
		OrderStatus  int8      `gorm:"column:order_status;comment:订单状态 1待确认 2已同意 3已拒绝 4:乘客取消 5自动取消;" db:"order_status" json:"order_status" form:"order_status"` //订单状态，1：待确认，2：已同意，3：已拒绝, 4:乘客取消，5：自动取消
		TripStatus   int8      `gorm:"column:trip_status;comment:1进行中 2等待发车 3司机取消;" db:"trip_status" json:"trip_status" form:"trip_status"`                     //冗余行程表状态，1：进行中，2：等待发车，3：司机取消
		Replay       string    `gorm:"type:varchar(255);comment:司机回复的内容;" db:"replay" json:"replay" form:"replay"`                                              //司机回复的内容
		Snapshot     string    `gorm:"column:snapshot;comment:快照;" db:"snapshot" json:"snapshot" form:"snapshot"`                                               //快照

		models.CommonTimestampsField
	}

	up := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.AutoMigrate(&TripRider{})
	}

	down := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.DropTable(&TripRider{})
	}

	migrate.Add("2023_07_18_141255_add_trip_riders_table", up, down)
}
